home *** CD-ROM | disk | FTP | other *** search
- Path: news.ccs.queensu.ca!news
- From: Wintermute <3mal5@qlink.queensu.ca>
- Newsgroups: comp.lang.c++
- Subject: Re: fast find algoritm?
- Date: Thu, 04 Apr 1996 08:08:11 -0500
- Organization: System Infinity
- Message-ID: <3163C9BB.3829@qlink.queensu.ca>
- References: <Dp8wE7.8E3@cix.compulink.co.uk> <4juj1r$kt8@bilbo.nask.org.pl> <4k01ui$sl2@grimsel.zurich.ibm.com>
- NNTP-Posting-Host: qlink.queensu.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; qlink 5.4 sun4d)
-
- Keith Whittingham wrote:
- >
- > In <4juj1r$kt8@bilbo.nask.org.pl>, flssoft@blue.maloka.waw.pl (Grzegorz (FLS)) writes:
- > >setheridge@cix.compulink.co.uk ("Stephen Etheridge") wrote:
- > >
- > >>Does anyone have an search algoritm faster than a binary chop for the
- > >>following:
- > >Yes, there is an algorithm with cost O(1). Use a hash-table. If you
- > >use a good hash-function, you will have a fastest algorithm.
- > >
- >
- > I doubt this is faster than a binary chop it the storage mechanism is
- > efficient and with only 1500 entries...
- >
- > Keith
-
- 2^11 = 2048, so you need at least 11 binary chops to search the table.
- With pointer dereferencing, etc., that'll likely take longer than a quick
- hash function.
-
- The hash function, however, will require some sort of collision resolution
- scheme. That can be avoided if your data is really random and your hash
- function is good, or perhaps you can even design a quick perfect hash
- function, the ideal.
-
- In the final analysis, you can easily calculate the worst case for a
- binary search, by which I mean summing the number of comparisons and
- additions and function calls required.
-
- Then you can do the same for the hash function, and obtain an average (or
- worst case) measurement for collision frequencies. Just use the best.
- Hope this helps.
-
- --
- Wintermute <3mal5@qlink.queensu.ca> <http://qlink.queensu.ca/~3mal5/>
-
- "If I really knew how to write, I could write something that someone
- could read and it would kill them." - william s. burroughs
-